home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Sierp2Form
- Caption = "Sierpinski Gasket"
- ClientHeight = 4335
- ClientLeft = 2280
- ClientTop = 1185
- ClientWidth = 5400
- Height = 5025
- Left = 2220
- LinkTopic = "Form1"
- ScaleHeight = 289
- ScaleMode = 3 'Pixel
- ScaleWidth = 360
- Top = 555
- Width = 5520
- Begin VB.TextBox LevelText
- Height = 285
- Left = 600
- MaxLength = 3
- TabIndex = 0
- Text = "5"
- Top = 0
- Width = 375
- End
- Begin VB.PictureBox Canvas
- AutoRedraw = -1 'True
- FillStyle = 0 'Solid
- Height = 4335
- Left = 1080
- ScaleHeight = 285
- ScaleMode = 3 'Pixel
- ScaleWidth = 277
- TabIndex = 3
- Top = 0
- Width = 4215
- End
- Begin VB.CommandButton CmdGo
- Caption = "Go"
- Default = -1 'True
- Height = 495
- Left = 120
- TabIndex = 1
- Top = 480
- Width = 735
- End
- Begin VB.Label Label1
- Caption = "Level"
- Height = 255
- Index = 0
- Left = 0
- TabIndex = 2
- Top = 0
- Width = 495
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "Sierp2Form"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim TheLevel As Integer
- Dim StartX(1 To 3) As Single
- Dim StartY(1 To 3) As Single
- ' ************************************************
- ' Draw a Sierpinski gasket.
- ' ************************************************
- Sub SierpGasket(level As Integer, x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As Single)
- Dim newy As Single
- Dim newx1 As Single
- Dim newx2 As Single
- Dim newx3 As Single
- Dim pt(1 To 3) As POINTAPI
- Dim status As Long
- ' Draw a filled in polygon.
- Canvas.FillColor = vbBlack
- pt(1).x = x1
- pt(1).y = y1
- pt(2).x = x2
- pt(2).y = y2
- pt(3).x = x3
- pt(3).y = y3
- status = Polygon(Canvas.hdc, pt(1), 3)
-
- ' If this is a level 0 gasket, we're done.
- If level < 1 Then Exit Sub
-
- ' Find the corners of the sub-triangles.
- newy = (y1 + y2) / 2
- newx1 = (3 * x1 + x3) / 4
- newx2 = (x1 + x3) / 2
- newx3 = (x1 + 3 * x3) / 4
- ' Erase the middle triangle.
- Canvas.FillColor = Canvas.BackColor
- pt(1).x = newx1
- pt(1).y = newy
- pt(2).x = newx3
- pt(2).y = newy
- pt(3).x = newx2
- pt(3).y = y1
- status = Polygon(Canvas.hdc, pt(1), 3)
- ' Recursively make the other gaskets.
- SierpGasket level - 1, x1, y1, newx1, newy, newx2, y1
- SierpGasket level - 1, newx1, newy, newx2, y2, newx3, newy
- SierpGasket level - 1, newx2, y1, newx3, newy, x3, y1
- End Sub
- Sub GetParameters()
- If Not IsNumeric(LevelText.Text) Then _
- LevelText.Text = "5"
- TheLevel = CInt(LevelText.Text)
- End Sub
- Private Sub CmdGo_Click()
- Dim i As Integer
- MousePointer = vbHourglass
- DoEvents
- ' Get the parameters.
- GetParameters
- ' Draw the curve.
- Canvas.Cls
- SierpGasket TheLevel, StartX(1), StartY(1), StartX(2), StartY(2), StartX(3), StartY(3)
- MousePointer = vbDefault
- End Sub
- Private Sub Form_Resize()
- Canvas.Move Canvas.Left, 0, _
- ScaleWidth - Canvas.Left, ScaleHeight - 1
- ' See where the first corners should be.
- StartX(1) = Canvas.ScaleWidth * 0.05
- StartX(2) = Canvas.ScaleWidth * 0.5
- StartX(3) = Canvas.ScaleWidth * 0.95
- StartY(1) = Canvas.ScaleHeight * 0.95
- StartY(2) = Canvas.ScaleHeight * 0.05
- StartY(3) = StartY(1)
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-